package com.cyp.productservice.controller;


import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.cyp.productservice.entity.Product;
import com.cyp.productservice.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;
    @GetMapping("/demo")
    public String demo() {
        return "product";
    }
    @GetMapping("/getProductList")
    public String getProductList() {
        return new Gson().toJson(productService.getProductList());
    }
    @GetMapping("/getProductById")
    public String getProductById(Long id) {
        return new Gson().toJson(productService.getProductById(id));
    }
    @GetMapping("/updateProduct")
    public Integer updateProduct(int quantity,Long id,Long userId) {
        return productService.updateProduct(quantity,id,userId);
    }
    @GetMapping("/getRedis")
    public List<Map<String, Object>> getRedis() {
        return productService.getRedis();
    }
}